﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ATEC.ATDataCoreNET;

namespace ATSceneExample
{
    public partial class ATSceneManagerForm : Form
    {
        private List<SceneManagerInfo> SceneInfos = new List<SceneManagerInfo>();
        private static Point s_Location = new Point(-1);

        public ATSceneManagerForm(List<SceneManagerInfo> sceneInfos)
        {
            InitializeComponent();
            SceneDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
            SceneDataGridView.AutoGenerateColumns = false;

            if (s_Location.X < 0)
            {
                s_Location.X = (int)((Screen.PrimaryScreen.Bounds.Width - Width) / 2);
                s_Location.Y = (int)((Screen.PrimaryScreen.Bounds.Height - Height) / 2);
            }

            this.Location = s_Location;

            SceneInfos = sceneInfos;
            SceneDataGridView.DataSource = SceneInfos;
        }

        private void ATSceneManagerForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            s_Location = this.Location;
        }

        private void SceneDataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.RowIndex > SceneInfos.Count - 1)
                return;

            string sceneName = SceneInfos[e.RowIndex].SceneName;

            ATProject activeProject = ATEC.ATCore.Session.Entity.GetActiveATProject();
            ATScene scene = ATSceneMethod.GetATScene(activeProject, sceneName);
            if (!scene.IsValid())
                return;

            SSDPNET.ATView.ViewSetScene(scene, 2);
            SSDPNET.ATView.ViewUpdateSingle(2);
        }

        private void SceneDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
    public class SceneManagerInfo
    {
        public string SceneName { get; set; }
    }
}
